<?php
class Knowledges_Controller extends Template_Controller {

	public $template = 'client/index';
	
    public function __construct()
    {
        parent::__construct();
        
        //Css
        //$this->template->css = $this->site['theme_url'].'index/article.css';
       
    }
    
	public function __call($method, $arguments)
	{
		// Disable auto-rendering
		$this->auto_render = FALSE;
	}
	
    public function index()
    {	
		$this->knowledge_type();
    }
     public function knowledge_type()
    {
    	$language= $this->get_client_lang();
		$this->template->content = new View('knowledges/type');
		$model = new Knowledges_type_Model(); 
		$mlist = $model->get_with_active($language);
		//Per page
		if(!isset($per_page))
			$per_page = $this->site['site_num_line']; 
		$this->pagination = new Pagination(array(
			'base_url'    => 'knowledges',
			'uri_segment'    => 'page',
			'total_items'    => count($mlist),
			'items_per_page' => $per_page,
			'style'          => 'digg',
		));	
		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);		
		$mlist = $model->get_with_active($language);
		$this->template->content->mlist= $mlist;
		
    }
	 public function type_detail($id)
    {
    	$this->db->where('knowledges_type_id',$id);
		$language= $this->get_client_lang();
		$this->template->content = new View('knowledges/type_detail');
		$model = new Knowledges_Model(); 
		$mlist = $model->get_with_active($language);
		//Per page
		if(!isset($per_page))
			$per_page = $this->site['site_num_line']; 
		$this->pagination = new Pagination(array(
			'base_url'    => 'knowledges',
			'uri_segment'    => 'page',
			'total_items'    => count($mlist),
			'items_per_page' => $per_page,
			'style'          => 'digg',
		));	
		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);		
		$this->db->where('knowledges_type_id',$id);
		$mlist = $model->get_with_active($language);
		$this->template->content->mlist= $mlist;
		$this->template->content->mrtitle= $this->get_type($id);
		
		
    }
	 public function get_type($id)
    {
    	$language = $this->get_client_lang();
		$model = new Knowledges_type_Model(); 
		$this->db->where('knowledges_type_content.knowledges_type_id',$id);
		$mlist = $model->get_with_active($language);
    	return $mlist[0];
    }
	public function page()
    {
    	$language= $this->get_client_lang();
		$this->template->content = new View('knowledges/index');
		$model = new Knowledges_Model(); 
		$mlist = $model->get_with_active($language);
		//Per page
		if(!isset($per_page))
			$per_page = $this->site['site_num_line']; 
		$this->pagination = new Pagination(array(
			'base_url'    => 'knowledges',
			'uri_segment'    => 'page',
			'total_items'    => count($mlist),
			'items_per_page' => $per_page,
			'style'          => 'digg',
		));	
		$this->db->limit($this->pagination->items_per_page,$this->pagination->sql_offset);		
		$mlist = $model->get_with_active($language);
		$this->template->content->mlist= $mlist;
		
    }
    public function detail($id)
    {
    	$this->template->content = new View('knowledges/detail');
    	$language = $this->get_client_lang();
		$model = new Knowledges_Model(); 
		$this->db->where('knowledges_content.knowledges_id',$id);
		$mlist = $model->get_with_active($language);
    	$this->template->content->mr = $mlist[0];
		$mlistOther = $this->other_knowledge($id);
		//print_r($mlistOther);
		$this->template->content->mlistOther = $mlistOther;
    }
	public function other_knowledge($id)

    {

    	$language = $this->get_client_lang();

		$model = new Knowledges_Model(); 

		$this->db->where('knowledges.knowledges_id <>',$id);

		$mlist = $model->get_with_active($language);

    	return $mlist;

    }
}
?>